package com.atguigu.auth.controller;

import com.atguigu.auth.service.WechatMenuService;
import com.atguigu.common.Result;
import com.atguigu.model.wechat.Menu;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: WechatMenuController
 * Package: com.atguigu.auth.controller
 * Description:
 *
 * @Author 蹇泽阳
 * @Create 2023/11/23 8:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/wechat/menu")
public class WechatMenuController {
  @Autowired
  private WechatMenuService menuService;
  
  
  //@PreAuthorize("hasAuthority('bnt.menu.list')")
  @ApiOperation(value = "获取")
  @GetMapping("get/{id}")
  public Result get(@PathVariable Long id) {
    Menu menu = menuService.getById(id);
    return Result.ok(menu);
  }
  
  //@PreAuthorize("hasAuthority('bnt.menu.add')")
  @ApiOperation(value = "新增")
  @PostMapping("save")
  public Result save(@RequestBody Menu menu) {
    menuService.save(menu);
    return Result.ok();
  }
  
  //@PreAuthorize("hasAuthority('bnt.menu.update')")
  @ApiOperation(value = "修改")
  @PutMapping("update")
  public Result updateById(@RequestBody Menu menu) {
    menuService.updateById(menu);
    return Result.ok();
  }
  
  //@PreAuthorize("hasAuthority('bnt.menu.remove')")
  @ApiOperation(value = "删除")
  @DeleteMapping("remove/{id}")
  public Result remove(@PathVariable Long id) {
    menuService.removeById(id);
    return Result.ok();
  }
  
  //@PreAuthorize("hasAuthority('bnt.menu.list')")
  @ApiOperation(value = "获取全部菜单")
  @GetMapping("findMenuInfo")
  public Result findMenuInfo() {
    return Result.ok(menuService.findMenuInfo());
  }
  
  //@PreAuthorize("hasAuthority('bnt.menu.syncMenu')")
  @ApiOperation(value = "同步菜单")
  @GetMapping("syncMenu")
  public Result createMenu() {
    menuService.syncMenu();
    return Result.ok();
  }
  
  @PreAuthorize("hasAuthority('bnt.menu.removeMenu')")
  @ApiOperation(value = "删除菜单")
  @DeleteMapping("removeMenu")
  public Result removeMenu() {
    menuService.removeMenu();
    return Result.ok();
  }
}
